package builder.banks;

import android.content.Context;
import android.telephony.TelephonyManager;
import android.util.Log;
import builder.AbstractOperations;
import builder.BankDataModel;
import builder.OperationNotAllowedException;

/**
 * Created by Vyacheslav on 07.07.2014.
 */
public class KredoBankOperations implements AbstractOperations {

    private String bankPhone = "80931777744";
    private String bankPhoneMTSOnly = "10912";
    private int[] mtsCodes = {38050, 38066, 38095, 38099};

    private Context context;

    public KredoBankOperations(Context context) {
        this.context = context;
    }

    @Override
    public String getBalance(BankDataModel model) {
        return new StringBuilder().append("1").append("#").append(model.getAccessCode()).append(" ").append("1").toString();
    }

    @Override
    public String blockCard(BankDataModel model) {
        throw new OperationNotAllowedException();
    }

    @Override
    public String getReport(BankDataModel model) {
        throw new OperationNotAllowedException();
    }

    @Override
    public String moneyTransfer(BankDataModel model) {
        throw new OperationNotAllowedException();
    }

    @Override
    public String unblockCard(BankDataModel model) {
        throw new OperationNotAllowedException();
    }

    @Override
    public String mobileTransfer(BankDataModel model) {
        throw new OperationNotAllowedException();
    }

    @Override
    public String getBankPhone() {
        if (isMtsNumberCheck()) {
            return bankPhoneMTSOnly;
        }
        return bankPhone;
    }

    /**
     * Метод проверяет номер абонента на принадлежность к оператору MTS
     * @return результат проверки
     */

    public boolean isMtsNumberCheck() {
        TelephonyManager tMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String phoneNumber = tMgr.getLine1Number();
        phoneNumber = phoneNumber.substring(0, 5);
        for (int mtsCode : mtsCodes) {
            Log.d("MyLogs", phoneNumber);
            if (mtsCode == Integer.parseInt(phoneNumber)) {
                return true;
            }
        }
        return false;
    }

}
